<?php
defined('IN_TS') or die('Access Denied.');

//小组首页

$groupid = intval($_GET['groupid']);

$typeid = intval($_GET['typeid']);

//小组信息
$strGroup = $new['group']->getOneGroup($groupid);

if($strGroup == '') header("Location: index.php");

$strGroup['recoverynum'] = $DB->once_num_rows("select * from ".dbprefix."app_group_topics where groupid='$groupid' and isshow='1'");

$pattern='/(http:\/\/|https:\/\/|ftp:\/\/)([\w:\/\.\?=&-_]+)/is';

$strGroup['groupdesc'] = hview(preg_replace($pattern, '<a href="\1\2">\1\2</a>', $strGroup['groupdesc']));

$title = $strGroup['groupname'];

//小组帖子分类
$arrTopicTypes = $DB->fetch_all_assoc("select * from ".dbprefix."app_group_topics_type where groupid='$groupid'");
if(is_array($arrTopicTypes)){
	foreach($arrTopicTypes as $item){
		$arrTopicType[$item['typeid']] = $item;
	}
}

//组长信息
$leaderId = $strGroup['userid'];

$strLeader = $DB->once_fetch_assoc("select * from ".dbprefix."app_user_info where userid='$leaderId'");

//判断会员是否加入该小组
$userid = $TS_USER['user']['userid'];

$isGroupUser = $DB->once_num_rows("select * from ".dbprefix."app_group_users where userid='$userid' and groupid='$groupid'");


//小组是否需要审核
if($strGroup['isaudit']=='1'){
	//推荐小组
	$arrRecommendGroup = $new['group']->getRecommendGroup('7');
	include TmooTemplate("group_isaudit");
	
}elseif($strGroup['isopen']=='1' && $isGroupUser=='0'){
	//是否开放访问
	include TmooTemplate("group_isopen");
}else{
	
	if($typeid == '0'){
		$andType = '';
	}else{
		$andType = "and typeid='$typeid'";
	}
	
	$sql = "select * from ".dbprefix."app_group_topics where groupid='$groupid' ".$andType." and isshow='0' order by istop desc,uptime desc limit 30";
	
	$arrGroupContents = $DB->fetch_all_assoc($sql);
	if(is_array($arrGroupContents)){
	foreach($arrGroupContents as $key=>$item){
		$arrGroupContent[] = $item;
		$arrGroupContent[$key]['typename'] = $arrTopicType[$item['typeid']]['typename'];
	}
	}
	
	//小组会员
	$groupUser = $DB->fetch_all_assoc("select userid from ".dbprefix."app_group_users where groupid='$groupid' order by addtime DESC limit 8");
	
	if(is_array($groupUser)){
		foreach($groupUser as $item){
			$arrGroupUser[] = aac('user',$DB)->getUserForApp($item['userid']);
		}
	}

	include TmooTemplate("group");

}